<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="ko">
<head>
	<title>메뉴관리</title>
	<link rel="stylesheet" type="text/css" href="../css/jquery.treeview.css" />	
	<script src="../js/jquery.js" type="text/javascript"></script>
	<script src="../js/jquery.cookie.js" type="text/javascript"></script>
	<script src="../js/jquery.treeview.js" type="text/javascript"></script>
	<script src="../js/validator.js" type="text/javascript"></script>
	<script type="text/javascript">
        $(function() {
            $("#tree").treeview({
                collapsed: true,
                animated: "medium",
                control:"#sidetreecontrol",
                persist: "location"
            });
        })
        
        function setMenu(sid, name, url, depth, parent, path, pathname)
        {
        	document.getElementById("choiceMenu").innerHTML = pathname;
        	
        	var frm1 = document.forms["writeFrm"];
        	var frm2 = document.forms["editFrm"];
        	var frm3 = document.forms["deleteFrm"];

        	frm1.menu_depth.value = Math.floor(depth) + 1;
        	frm1.parent_sid.value = sid;
        	frm1.menu_path.value = path;
        	frm1.menu_pathname.value = pathname;

        	frm2.menu_sid.value = sid;
        	frm2.menu_name.value = name;
        	frm2.menu_url.value = url;
        	frm2.menu_depth.value = depth;
        	frm2.parent_sid.value = parent;
        	frm2.menu_path.value = path;
        	frm2.menu_pathname.value = pathname;
        	
        	frm3.menu_sid.value = sid;
        	frm3.menu_name.value = name;
        	frm3.menu_url.value = url;
        	frm3.menu_depth.value = depth;
        	frm3.parent_sid.value = parent;
        	frm3.menu_path.value = path;
        	frm3.menu_pathname.value = pathname;
        }

        function reg(frm)
        {
			if(!checkAuth()) return false;
        	if (frm.menu_depth.value > 3)
       		{
				alert("더이상 하위 메뉴를 생성할 수 없습니다.");
				return false;
       		}
    		if (!isTextValidate(frm.menu_name, "string", 0, "메뉴명"))			return false;
    		if (!isTextValidate(frm.menu_url, "string", 0, "메뉴URL"))			return false;

    		return true;
        }

        function edit(frm)
        {
			if(!checkAuth()) return false;
    		if (!isTextValidate(frm.menu_sid, "string", 0, "수정메뉴"))			return false;
    		if (!isTextValidate(frm.menu_name, "string", 0, "메뉴명"))			return false;
    		if (!isTextValidate(frm.menu_url, "string", 0, "메뉴URL"))			return false;

    		return true;
        }

        function del(frm)
        {
			if(!checkAuth()) return false;
        	if (confirm("삭제하시겠습니까?"))
       		{
        		if (!isTextValidate(frm.menu_sid, "string", 0, "삭제메뉴"))			return false;
        		if (!isTextValidate(frm.menu_name, "string", 0, "메뉴명"))			return false;
        		if (!isTextValidate(frm.menu_url, "string", 0, "메뉴URL"))			return false;

        		return true;
       		}

        	return false;
        }
    </script>
</head>

<body>
		<!-- 본문 영역 -->
		<div id="contents">
			<!-- 제목 및 Location 영역 -->
			<div id="location">
				<h3>메뉴관리</h3>
				<div>홈 &gt; 관리메뉴 &gt; <strong>메뉴관리</strong></div>
			</div>

			<!-- 본문 내용 -->
			<div id="content">
				<div style="width:40%; float:left;">
					<ul id="tree">
				<c:forEach items="${listMap}" var="listMap1" varStatus="status">
					<c:if test="${listMap1.MENU_DEPTH eq '1' }">
				        <li>
				        	<a href="#" onclick="setMenu('${listMap1.MENU_SID}','${listMap1.MENU_NAME}','${listMap1.MENU_URL}','${listMap1.MENU_DEPTH}','${listMap1.PARENT_SID}','${listMap1.MENU_PATH}','${listMap1.MENU_PATHNAME}'); return false;">
				            	<strong>${listMap1.MENU_NAME}</strong>
				            </a>
				            <ul>
						<c:forEach items="${listMap}" var="listMap2">
							<c:if test="${ listMap2.PARENT_SID eq listMap1.MENU_SID and listMap2.MENU_DEPTH eq '2' }">
				                <li>
						        	<a href="#" onclick="setMenu('${listMap2.MENU_SID}','${listMap2.MENU_NAME}','${listMap2.MENU_URL}','${listMap2.MENU_DEPTH}','${listMap2.PARENT_SID}','${listMap2.MENU_PATH}','${listMap2.MENU_PATHNAME}'); return false;">
						            	${listMap2.MENU_NAME}
						            </a>
				                    <ul>
								<c:forEach items="${listMap}" var="listMap3">
									<c:if test="${ listMap3.PARENT_SID eq listMap2.MENU_SID and listMap3.MENU_DEPTH eq '3' }">
				                        <li>
								        	<a href="#" onclick="setMenu('${listMap3.MENU_SID}','${listMap3.MENU_NAME}','${listMap3.MENU_URL}','${listMap3.MENU_DEPTH}','${listMap3.PARENT_SID}','${listMap3.MENU_PATH}','${listMap3.MENU_PATHNAME}'); return false;">
								            	${listMap3.MENU_NAME}
								            </a>
				                        </li>
					            	</c:if>
					            </c:forEach>
				                    </ul>
				                </li>
			            	</c:if>
			            </c:forEach>
				            </ul>
				        </li>
					</c:if>
				</c:forEach>
				    </ul>
				</div>
				<div>
					<div  style="width:55%; padding-left:10px; float:left;">
						<p>선택된 메뉴 : <span id="choiceMenu"> </span></p>
						<div class="t10">
							<form name="writeFrm" method="post" action="../admin/menumng_proc.do" onsubmit="return reg(this);">
							<input type="hidden" name="mode" value="write" />
							<input type="hidden" name="super_yn" value="N" />
							<input type="hidden" name="menu_depth" value="1" />
							<input type="hidden" name="parent_sid" value="" />
							<input type="hidden" name="menu_path" value="" />
							<input type="hidden" name="menu_pathname" value="" />
							<input type="text" name="menu_name" size="20" />
							<input type="text" name="menu_url" size="40" />
							<span class="button btnProc01">
								<input type="submit" value="등록" />
							</span>
							</form>
						</div>

						<div class="t10">
							<form name="editFrm" method="post" action="../admin/menumng_proc.do" onsubmit="return edit(this);">
							<input type="hidden" name="mode" value="edit" />
							<input type="hidden" name="super_yn" value="N" />
							<input type="hidden" name="menu_sid" />
							<input type="hidden" name="menu_depth" />
							<input type="hidden" name="parent_sid" />
							<input type="hidden" name="menu_path" />
							<input type="hidden" name="menu_pathname" />
							<input type="text" name="menu_name" size="20" />
							<input type="text" name="menu_url" size="40" />
							<span class="button btnProc01">
								<input type="submit" value="수정" />
							</span>
							</form>
						</div>

						<div class="t10">
							<form name="deleteFrm" method="post" action="../admin/menumng_proc.do" onsubmit="return del(this);">
							<input type="hidden" name="mode" value="delete" />
							<input type="hidden" name="super_yn" value="N" />
							<input type="hidden" name="menu_sid" />
							<input type="hidden" name="menu_depth" />
							<input type="hidden" name="parent_sid" />
							<input type="hidden" name="menu_path" />
							<input type="hidden" name="menu_pathname" />
							<input type="text" name="menu_name" size="20" readonly="readonly" />
							<input type="text" name="menu_url" size="40" readonly="readonly" />
							<span class="button btnProc01">
								<input type="submit" value="삭제" />
							</span>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
</body>
</html>